package cn.linjianhui.api.client.config;

import cn.linjianhui.api.client.exception.RpcClientException;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

@Getter
@Setter
@Component
@ConfigurationProperties(prefix = RpcClientConstant.ROOT_CONFIG_PREFIX)
public class RpcClientConfig {
    private String userName;
    private String userPass;
    private String baseAddress;
    private String appKey;
    private String appSecret;
    private String netProxy;

    public String getUserPass() {
        if(!StringUtils.hasText(userPass)) {
            throw new RpcClientException("api config user-pass is null");
        }
        return userPass;
    }

    public String getBaseAddress() {
        if(!StringUtils.hasText(baseAddress)) {
            throw new RpcClientException("api config base-address is null");
        }
        return StringUtils.trimTrailingCharacter(baseAddress, '/');
    }

    public String getUserName() {
        if(!StringUtils.hasText(userName)) {
            throw new RpcClientException("api config user-name is null");
        }
        return userName;
    }

    public String getAppKey() {
        if(!StringUtils.hasText(appKey)) {
            throw new RpcClientException("api config app-key is null");
        }
        return appKey;
    }

    public String getAppSecret() {
        if(!StringUtils.hasText(appSecret)) {
            throw new RpcClientException("api config app-secret is null");
        }
        return appSecret;
    }
}
